<?php

namespace App\Service\H5;

use App\Service\BaseService;
use Hyperf\DbConnection\Db;

/**
 * 封禁账号
 */
class ViolationPublicizeService extends BaseService
{
    public function handle()
    {
        return $this->getInfo();
    }

    function getInfo()
    {
        $data = Db::select('select * from t_banned_notice_logs order by id desc limit 50');

        $returnData = [];
        foreach ($data as $item) {
            $returnData[] = [
                'userId' => substr_replace($item->user_profile_id,'***',2,3),
                'typeStr' => $item->type_str,
                'bannedStr' => $item->banned_str,
            ];
        }

        return $returnData;
    }

    function substrCut($userName)
    {
        //获取字符串长度
        $strlen = mb_strlen($userName, 'utf-8');
        //如果字符创长度小于2，不做任何处理
        if ($strlen < 2) {
            return mb_substr($userName, 0, 1, 'utf-8').'*';
        } else {
            //mb_substr — 获取字符串的部分
            $firstStr = mb_substr($userName, 0, 1, 'utf-8');
            $lastStr = mb_substr($userName, -1, 1, 'utf-8');
            //str_repeat — 重复一个字符串
            return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($userName, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
        }
    }
}
